This week we were asked to write an application that interfaces with an input or output device that we made. Both Anya and Nathan suggested that I start with Processing, as it is easier to play with for beginners. I have kept my example simple as I don't anticipate doing a lot of interface or application programming for my final project. I managed to get Processing to recognize the signals that my passive infrared motion sensor sent and change the color of the square whenever it detected a motion. I modified one of the example codes in Processing with the help from Rob and Tiffany. Here is the file and here is an image of the codes with some of my annotations:
A few things I wanted to mention about the code:
The "printArray(Serial.list())" statement helped display the name of the serial port. I could alternatively use CoolTerm to find out the name of the serial port that I was using. This name was essential for defining the "portName" variable.
The "draw()" function has an inherent infinite loop, so when I tried to add the "while(true)" loop within the function it did not work.
Inspired by the "printArray" statement, I added a "print(val)" statement so that I could see what value was being read and stored in the variable "val". Initially I thought the values would be either 0 or 1; but I noticed that the "if(val == 0)" statement was not doing anything. Then Rob suggested that I view the hex code in CoolTerm; and we realized that the values being sent to CoolTerm were actually 30 and 31. With the "print(val)" statement, we could see that when there was no motion, val was 48, and when there was motion, val was 49. With these values, we modified the conditional statements accordingly, and they finally worked.
Tiffany showed me how to use RGB combinations in the "background()" and "fill()" functions to indicate different colors. The square would be blue if there was no motion and turn yellow when motion was detected.
As can be seen in the video below, whenever there was motion, the square would turn yellow and the LED on the board would turn on:
This week I also tried to make Neil's RGB board and install Python and Pyserial on my Windows PC.
RGB Board
I didn't have time to make an RGB LED board during the "Output Devices" week. So I made Neil's board this week. Similar to last week, I had to deburr the board a little bit with sand paper after milling it:
When I tried to program the board I kept on getting the "rc=-1" connection error.
I checked to make sure that none of the components looked overheated, that the RGB board was properly powered and that my programmer board was functioning. After staring at the board for quite some time and not being able to detect any points of poor soldering, I decided to replace the Attiny45 microcontroller (even though the casing looked perfectly fine) as suggested by many people who posted about this error online. And that actually did the trick!
Installing Python and Pyserial on Windows
With some great help from Harry, I was able to install Python and pyserial, and get them to recognize my serial port. Here are the steps that I took:
Unzip pyserial-2.7.tar.gz, in the folder "pyserial-2.7", find the folder named "serial". Copy/paste this folder into "C:\Python27\Lib\site-packages" folder
Under "Control Panel", search for "environment" to bring up the environment variable settings. Add "C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;" to the "Path" variable under "System Variables". I initially followed this tutorial to set up the PATH variable under the "User Variables" section. They should both be okay.
I wanted to thank Rob, Anya, Nathan, Tiffany and Harry for their help this week!